from fastapi import APIRouter

from app.niuniu.apis import *
from standard_response import StandardResponseItem

router = APIRouter(prefix='/niuniu/api')


@router.get('/create_room/{user_id}')
async def create_room(user_id: str):
    await Room.create(user_id)
    return StandardResponseItem()


@router.get('/join_room/{room_id}/{user_id}')
async def join_room(room_id: str, user_id: str, last_room_id: str = ""):
    if last_room_id:
        await Room.leave(last_room_id, user_id)
    await Room.join(room_id, user_id)
    return StandardResponseItem()


@router.get('/leave_room/{room_id}/{user_id}')
async def leave_room(room_id: str, user_id: str):
    await Room.leave(room_id, user_id)
    return StandardResponseItem()


@router.get('/delete_room/{room_id}/{user_id}')
async def delete_room(room_id: str, user_id: str):
    await Room.delete(room_id, user_id)
    return StandardResponseItem()


@router.get('/all_room')
async def all_room():
    data = await Room.all_room()
    return StandardResponseItem(data=data)


@router.get('/room_info/{room_id}')
async def room_info(room_id: str):
    data = await Room.info(room_id)
    return StandardResponseItem(data=data)
